package com.example.mystoryapp2.ui.user.regist

import android.annotation.SuppressLint
import android.text.TextUtils
import android.widget.ArrayAdapter
import androidx.lifecycle.MutableLiveData
import com.example.mystoryapp2.R
import com.example.mystoryapp2.contexts.AppContext
import com.example.mystoryapp2.data.network.model.UserModel
import com.example.mystoryapp2.enums.EnumRole
import com.example.mystoryapp2.ui.base.BaseViewModel
import com.example.mystoryapp2.ui.utils.DialogUtils

@SuppressLint("ResourceType")
class RegisterViewModel:BaseViewModel() {
    var username = MutableLiveData<String>()
    var password = MutableLiveData<String>()
    var confirmPassword = MutableLiveData<String>()
    var name = MutableLiveData<String>()
    var email = MutableLiveData<String>()
    var bio = MutableLiveData<String>()
    var role = String()
    var roleList = ArrayList<String>()
    lateinit var adapter:ArrayAdapter<String>
    init {

    }
    fun checkInputValid(): Boolean {
        if(TextUtils.isEmpty(password.value)){
            DialogUtils.showLongMessage(AppContext.application.baseContext,
                R.string.password_is_empty)
            return false
        }
        if(!TextUtils.equals(password.value,confirmPassword.value)){
            DialogUtils.showLongMessage(AppContext.application.baseContext,
                R.string.password_confirm_failed);
            return false
        }
        return true
    }

    fun loadUserinfo(callBack:UserModel.ICallBack){
        UserModel.loadUserinfo(callBack)
    }

    fun onItemSelected(pos:Int){
        role = (roleList[pos])
    }

}